package com.laboratory.manage.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laboratory.manage.dao.MemberDao;
import com.laboratory.manage.entity.MemberEntity;
import com.laboratory.manage.service.MemberService;
import com.laboratory.manage.utils.PageUtils;
import com.laboratory.manage.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * service实现类  集成MYBATIS-PLUS提供通用的service基类
 * ServiceImpl<MemberDao, MemberEntity>
 * 2个泛型1.MemberDao 接口
 *       2.MemberEntity 对应的实体类
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {
    //数据层接口
    @Autowired
    private MemberDao memberDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberEntity> page = this.page(new Query<MemberEntity>().getPage(params),
                new QueryWrapper<MemberEntity>()
        );
        return new PageUtils(page);
    }

    @Override
    public List<MemberEntity> getAll(){

        return memberDao.selectList(null);
    }

    @Override
    public MemberEntity getById(Integer id) {

        return memberDao.selectById(id);
    }

    @Override
    public boolean update(MemberEntity memberEntity) {

        int i = memberDao.updateById(memberEntity);
        if(i != 0){
            return true;
        }
        return false;
    }
}
